package com.xoa.controller.documentOrg;

import com.xoa.global.intercptor.CommonDatase;
import com.xoa.model.documentOrg.DocumentOrg;
import com.xoa.model.users.OrgManage;
import com.xoa.service.documentOrg.DocumentOrgService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.dataSource.ContextHolder;
import com.xoa.util.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Administrator on 2018/3/14.
 */
@Controller
@RequestMapping("/documentOrg")
public class DocumentOrgController {

    @Autowired
    DocumentOrgService documentOrgService;

    @RequestMapping("/issue")
    public String issue() {
        return "app/officialDocument/issue";
    }


    /*
    * 创建作者:   廉立深
    * 创建日期:   12:19 2019/12/3
    * 方法介绍:     下发公文查看未下发的机构
    * 参数说明:   [request, locales:公文ID]
    * @return     com.xoa.util.ToJson<com.xoa.model.users.OrgManage>
    */
    @RequestMapping(value = "/getCompanyAll", method = RequestMethod.GET)
    @ResponseBody
    public ToJson getCompanyAll(HttpServletRequest request, String locales) {
        return documentOrgService.querylistId(request,locales);
    }

    /**
     * 作者: 张航宁
     * 日期: 2018/3/14
     * 说明: 保存接口
     */
    @ResponseBody
    @RequestMapping("/save")
    public ToJson<DocumentOrg> save(Integer id, DocumentOrg documentOrg, HttpServletRequest request) {
        return documentOrgService.saveDoc(id, documentOrg, request);
    }

    /**
     * 说明: 根据流水号与转交后的接收组织进行查看是否已下发过一次
     */
    @ResponseBody
    @RequestMapping("select")
    public boolean select(Integer id, DocumentOrg documentOrg, HttpServletRequest request) {
        return documentOrgService.select(id, documentOrg, request);
    }

    /**
     * 作者: 张航宁
     * 日期: 2018/3/14
     * 说明: 查询接口
     */
    @ResponseBody
    @RequestMapping("/selDocumentOrg")
    public ToJson<DocumentOrg> selDocumentOrg(DocumentOrg documentOrg, HttpServletRequest request, PageParams pageParams) {
        return documentOrgService.selDocumentOrg(documentOrg, request, pageParams);
    }

    /**
     * 说明: 查询库中document_org表transfer_flag字段是否办理下发文件
     */
    @ResponseBody
    @RequestMapping("/selectDocumentOrgIsConduct")
    public ToJson<OrgManage> selectDocumentOrgIsConduct(DocumentOrg documentOrg, HttpServletRequest request) {
        ToJson<OrgManage> json = new ToJson<OrgManage>();
        List<OrgManage> orgManages = documentOrgService.selectDocumentOrgIsConduct(documentOrg, request);
        json.setObj(orgManages);
        return json;
    }


    /**
     * 说明: 查询库中document_org表transfer_flag字段是否办理下发文件
     */
    @ResponseBody
    @RequestMapping("/selectDocumentOrgIsConducts")
    public ToJson<OrgManage> selectDocumentOrgIsConducts(DocumentOrg documentOrg, HttpServletRequest request) {
        ToJson<OrgManage> json = new ToJson<OrgManage>();
        List<OrgManage> orgManages = null;
        try {
            orgManages = documentOrgService.selectDocumentOrgIsConducts(documentOrg, request);
        } catch (Exception e) {
            json.setObject(e.toString());
            json.setMsg("没有此表");
        }
        json.setObj(orgManages);
        return json;
    }

    /**
     * 作者: 张航宁
     * 日期: 2018/3/14
     * 说明: 上级来文转公文
     */
    @ResponseBody
    @RequestMapping("/saveToDocument")
    public ToJson<Object> saveToDocument(HttpServletRequest request, Integer id, Integer flowId, String documentType) {
        return documentOrgService.saveToDocument(request, id, flowId, documentType);
    }

}
